# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 -------------------------------------------------
    File Name:     framework_initializer.py
    Description:   测试框架初始化模块
    将缓存清理、用例加载、用例校验抽离到专门的 框架初始化模块，主入口文件只负责调用，便于后续扩展和优化
 -------------------------------------------------
 """
from apitesting.common.util.logger import log
from apitesting.src.case_manager import CaseManager, validate_case_data_from_redis
from apitesting.src.env_manager import check_environment
from apitesting.src.extensions import start_mock_service
from apitesting.src.log_manager import initialize_logging


class FrameworkInitializer:
    @staticmethod
    def initialize_framework(pydantic_verify=True):
        """初始化测试框架"""

        # 1. 初始化日志
        # initialize_logging()

        # 2. 检查运行环境
        check_environment()

        # 1. 清理缓存: 清理当前执行项目的所有缓存用例
        try:
            CaseManager.clean_redis_cache(clean_cache=False)
            log.info("✅ 缓存清理完成")
        except Exception as e:
            log.warning(f"⚠️ 缓存清理过程中出现问题: {e}")

        # 3. 加载测试用例
        # try:
        #     case_manager = CaseManager()
        #     case_manager.load_cases()
        #     log.info("✅ 用例数据初始化完成")
        # except Exception as e:
        #     log.error(f"❌ 用例数据初始化失败: {e}")
        #     raise RuntimeError(f"框架初始化失败") from e

        # 4. 启动扩展服务
        start_mock_service()
